/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dnbW.uiW.queryW.modelW;

import dnbW.dbW.PathExpression;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 * A static class to build all nodes in the condition tree
 * @author zhouyong
 */
public class ConditionNodeFactory {
    
    public static DefaultMutableTreeNode createOperatorNode(String op) {

        if (!op.equals(Operators.AND_OP) && !op.equals(Operators.OR_OP)) {
            return null;
        }
        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        OperatorNodeObject nodeObject = new OperatorNodeObject(node, op);
        node.setUserObject(nodeObject);
        return node;
    }

    public static DefaultMutableTreeNode createComparisonNode(
            PathExpression pathExpression,
            String operator,
            String value) 
    {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        ComparisonNodeObject nodeObject =
                new ComparisonNodeObject(node, pathExpression, operator, value);
        node.setUserObject(nodeObject);
        return node;
    }

    public static DefaultMutableTreeNode createXComparisonNode(
            PathExpression pathExpression,
            String operator,
            String value) 
    {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        ComparisonNodeObject object = 
                new XComparisonNodeObject(node, pathExpression, operator, value);
        node.setUserObject(object);
        return node;
    }
    
    public static DefaultMutableTreeNode createJoinNode(
            PathExpression leftPath, 
            PathExpression rightPath,
            String operator)
    {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        JoinNodeObject object =
                new JoinNodeObject(node, leftPath, rightPath, operator);
        node.setUserObject(object);
        return node;
    }
}
